package de.justphil.tcg.tcgserver.websockets.util;

import net.jcip.annotations.ThreadSafe;
import de.justphil.tcg.tcgserver.commons.util.StringUtil;
import de.justphil.tcg.tcgserver.game.mechanics.config.Config;
import de.justphil.tcg.tcgserver.websockets.messages.TCGJoinFragment;
import de.justphil.tcg.tcgserver.websockets.messages.TCGMessage;
import de.justphil.tcg.tcgserver.websockets.messages.TCGProgressFragment;
import de.justphil.tcg.tcgserver.websockets.messages.TCGProgressFragment.Command;

@ThreadSafe
public class MessageValidator {
	
	public static boolean isValidJoinMessage(TCGMessage msg) {
		TCGJoinFragment j = msg.getJoinFragment();
		return !(j == null || j.getGameId() <= 0 || j.getPlayerId() <= 0 || StringUtil.isNullOrEmpty(j.getOtp()));
	}
	
	public static boolean isValidResumeMessage(TCGMessage msg) {
		TCGProgressFragment p = msg.getProgressFragment();
		return !(p == null || StringUtil.isNullOrEmpty(p.getCommand()) || !Command.RESUME.equals(p.getCommand()));
	}
	
	public static boolean isValidSlotSelectedMessage(TCGMessage msg) {
		TCGProgressFragment p = msg.getProgressFragment();
		return !(	p == null									||
					StringUtil.isNullOrEmpty(p.getCommand())	||
					!Command.SELECT.equals(p.getCommand())		||
					p.getSlot() < 0								||
					p.getSlot() >= Config.NUM_SLOTS_PER_PLAYER 
				);
	}
}
